package com.ipad.ui.fragmen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ipad.R;
import com.ipad.bean.Warehouse;

import java.util.List;

/**
 * Created by sev-14 on 2018/5/9.
 */

public class WareHouseListV2Adapter extends BaseAdapter {
    List<Warehouse> wareHouseEntities;
    Context context;
    LayoutInflater inflater;

    public WareHouseListV2Adapter(List<Warehouse> wareHouseEntities, Context context) {
        this.wareHouseEntities = wareHouseEntities;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return wareHouseEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return wareHouseEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_warehouse,null);
            holder  = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.warehouse_name.setText(wareHouseEntities.get(position).getName());

        return convertView;
    }


    private static class ViewHolder{
        TextView warehouse_name;

        public ViewHolder(View view) {
            warehouse_name = view.findViewById(R.id.item_warehouse_name);
        }
    }
}
